// **************************************************************
// Copyright (c) 2021 Xidian University.
// File name     : np_interface.v
// Module name   : 
// Created Date  : 2022-04-15
// Author        : zhangjianyuan
// Email         : 
// -------------------------------------------------------------------------
// Version       : 
// Last Modified : 2022-04-29 12:44:08
// Modified By   : Wangzekun
// -------------------------------------------------------------------------
// 
// -------------------------------------------------------------------------
// HISTORY       : v0.2
// Date         By  Comments
// ------------ --  ----------------------------------------------------------
// v0.1--zhangjianyuan
// v0.2--modify input address from [18:0] to [16:0]
// 
`include "top_define.v"
// module scan_ME # (
//      parameter CLUSTER_ID = 2'b0
//   )
//   (
module scan_ME (
     input       [1:0] cluster_id
    ,input             clk
    ,input             rst_n
    ,input             np_rd_in
    ,input      [16:0] np_addr_in
    ,output reg [31:0] np_data_out
    ,output reg        np_data_out_vld
  );
//==================================================
reg np_rd;
always @(posedge clk or negedge rst_n) begin
    if(~rst_n)
        np_rd <= 1'b0;
    else if (np_rd_in)
        np_rd <= !(|np_addr_in[16:10]);
    else 
        np_rd <= 1'b0;
end

//---------------------------------------------------
reg [18:0]np_addr_in_d1;
always @(posedge clk or negedge rst_n) begin
    if(~rst_n)
        np_addr_in_d1 <= 1'b0;
    else if(np_rd_in)
        np_addr_in_d1 <= np_addr_in;
end

//---------------------------------------------------
always @(posedge clk or negedge rst_n) begin
    if(~rst_n)begin
        np_data_out <= 32'b0;
        np_data_out_vld <= 1'b0;
    end else if(np_rd)begin
        case(np_addr_in_d1[9:0])
            `ADDR_IDCODE_ME0:begin
                np_data_out <= {12'h19a,cluster_id,3'b000,15'h5889};
                np_data_out_vld <= 1'b1;
            end
            `ADDR_IDCODE_ME1:begin
                np_data_out <= {12'h19a,cluster_id,3'b001,15'h5889};
                np_data_out_vld <= 1'b1;
            end
            `ADDR_IDCODE_ME2:begin
                np_data_out <= {12'h19a,cluster_id,3'b010,15'h5889};
                np_data_out_vld <= 1'b1;
            end
            `ADDR_IDCODE_ME3:begin
                np_data_out <= {12'h19a,cluster_id,3'b011,15'h5889};
                np_data_out_vld <= 1'b1;
            end
            `ADDR_IDCODE_ME4:begin
                np_data_out <= {12'h19a,cluster_id,3'b100,15'h5889};
                np_data_out_vld <= 1'b1;
            end
            `ADDR_IDCODE_ME5:begin
                np_data_out <= {12'h19a,cluster_id,3'b101,15'h5889};
                np_data_out_vld <= 1'b1;
            end
            `ADDR_IDCODE_ME6:begin
                np_data_out <= {12'h19a,cluster_id,3'b110,15'h5889};
                np_data_out_vld <= 1'b1;
            end
            `ADDR_IDCODE_ME7:begin
                np_data_out <= {12'h19a,cluster_id,3'b111,15'h5889};
                np_data_out_vld <= 1'b1;
            end
            default:np_data_out_vld <= 1'b0;
        endcase
    end else begin
        np_data_out_vld <= 1'b0;
    end
end

endmodule